package com.hmdp.utils;
import org.springframework.web.servlet.HandlerInterceptor;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class LoginInterceptor implements HandlerInterceptor {

    /**
     * 登录校验
     */
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        //判断需要拦截threadlocal有用户
        if(UserHolder.getUser()==null){
            //没有，需要拦截器，设置状态码
            response.setStatus(401);
            //拦截
            return false;
        }
        return true;
    }
    }


